package gov.pbc.nn.core.bdf.view;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.core.CoreJdbcDao;
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.core.Configure;
import com.bstek.dorado.data.provider.Page;

@Component("loginImpl")
public class LoginImpl extends CoreJdbcDao {

	public void beforeInit() {
		if (Configure.getBoolean("sso")) {
			
		}
	}

	@DataProvider
	public List<Map<String, Object>> getAll(String username) {
		List<Map<String, Object>> lists = null;
		if (username != null) {
			String sql = "select u.USERNAME_,u.CNAME_ ,d.NAME_,d.ID_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  where  u.CNAME_ like concat(?,'%') or d.NAME_ like concat('%',?,'%') ";
			lists = this.getJdbcTemplate().queryForList(sql, new String[] { username, username });

		} else {
			String sql1 = "select u.USERNAME_,u.CNAME_ ,d.NAME_,d.ID_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  ";
			lists = this.getJdbcTemplate().queryForList(sql1);
		}
		return lists;
	}

	@DataProvider
	public List<Map<String, Object>> getAll(Page<Map<String, Object>> page, String username) {
		List<Map<String, Object>> lists = null;
		if (StringUtils.isNotBlank(username)) {
			String sql = "select u.USERNAME_,u.CNAME_ ,d.NAME_,d.ID_  from t_user u  INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_ INNER JOIN  t_dept d ON ud.DEPT_ID_=d.ID_  where  u.CNAME_ like ? or d.NAME_ like ? ";
			this.pagingQuery(page, sql, new Object[] { username + "%", username });
		} else {
			// String sql1 = "select u.USERNAME_,u.CNAME_ ,d.NAME_,d.ID_ from
			// t_user u INNER JOIN bdf2_user_dept ud on ud.USERNAME_=u.USERNAME_
			// INNER JOIN t_dept d ON ud.DEPT_ID_=d.ID_ ";
			// this.pagingQuery(page, sql1);
		}
		return lists;
	}

}
